/**
 * @Author:  renyc
 * @Date: 2022年12月21日21:00:36
 */

import * as Cesium from "cesium/Cesium";
import PrimitiveOverlay from "./PrimitiveOverlay";

/**
 * @class EllipsePrimitive
 */
class EllipsePrimitive extends PrimitiveOverlay{

    /**
     * 
     * @param {*} ellipse  
     * @param {*} options 
     * @description ellipse = {
     *      position : {
     *          lng : 116,
     *          lat : 39,
     *          alt : 0
     *      },
     *      semiMinorAxis: 1000,
     *      semiMajorAxis: 2000,
     * }
     */
    constructor(ellipse, options){
        super();
    
        this._ellipse = ellipse;
        this._options = options;
        this._delegate = undefined;

        if(this._ellipse){
            this._delegate = this._createPrimivive();
        }
    }

    _createPrimivive(){
        let position = this._ellipse.position;
        let geometry = new Cesium.EllipseGeometry({
            center : Cesium.Cartesian3.fromDegrees(position.lng, position.lat),
            semiMinorAxis : this._ellipse.semiMinorAxis,
            semiMajorAxis : this._ellipse.semiMajorAxis,
            rotation : Cesium.Math.PI_OVER_FOUR,
            vertexFormat : Cesium.VertexFormat.POSITION_AND_ST
        });
        let instance = new Cesium.GeometryInstance({
            id : this._id,
            geometry : geometry
        });        
        
        let appearance = new Cesium.EllipsoidSurfaceAppearance({
            material : Cesium.Material.fromType('Checkerboard')
        });
           
        let primitive = new Cesium.Primitive({
            geometryInstances : instance,
            appearance : appearance
        });

        return primitive;
    }
}

export default EllipsePrimitive